//
//  FlutterQQResponseHandler.m
//  Pods-Runner
//
//  Created by lu on 11/11/2019.
//

#import "FlutterQQResponseHandler.h"

@implementation FlutterQQResponseHandler

+ (instancetype)defaultManager {
    static dispatch_once_t onceToken;
    static FlutterQQResponseHandler *instance;
    dispatch_once(&onceToken, ^{
        instance = [[FlutterQQResponseHandler alloc] init];
    });
    return instance;
}

- (void)setMethodChannel:(FlutterMethodChannel *)flutterMethodChannel {
    _fluQQMethodChannel = flutterMethodChannel;
}

// MARK: - QQApiInterfaceDelegate

- (void)isOnlineResponse:(NSDictionary *)response {
    
}

- (void)onReq:(QQBaseReq *)req {
    NSLog(@"回调1");
}

- (void)onResp:(QQBaseResp *)resp {
    NSLog(@"回调2");
    if ([resp isKindOfClass:[SendMessageToQQResp class]])
    {// 分享// 0是成功 -4是取消
        SendMessageToQQResp *resp1 = (SendMessageToQQResp *)resp;
        NSLog(@"QQ分享: %@", resp1.result);
        
        if (resp1.type == ESENDMESSAGETOQQRESPTYPE && [resp1.result integerValue] == 0) {
            // 分享成功
            
            NSDictionary *result = @{
                    @"description": resp1.description == nil ? @"" : resp1.description,
                    @"errStr": resp1.errorDescription == nil ? @"" : resp1.errorDescription,
                    @"errCode": @(0),
                    @"type": resp1.type == 0 ? @2 : @(resp1.type)
            };
            
            NSLog(@"分享回调：成功");
            [_fluQQMethodChannel invokeMethod:@"onQQShareResponse" arguments:result];
        }else{
            NSLog(@"分享回调：失败");
            
            NSDictionary *result = @{
                    @"description": resp1.description == nil ? @"" : resp1.description,
                    @"errStr": resp1.errorDescription == nil ? @"" : resp1.errorDescription,
                    @"errCode": @(1),
                    @"type": resp1.type == 0 ? @2 : @(resp1.type)
            };
            
            [_fluQQMethodChannel invokeMethod:@"onQQShareResponse" arguments:result];
        }
    }
}

@end
